package com.moyq5.mvc.maker.test.bean.embed;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.PrePersist;

/**
 * 需要有状态查询记录的的实体抽象类
 * @author Moyq5
 * @date 2018年7月2日
 */
@Embeddable
public abstract class Query {

	/**
	 * 状态"已"查询次数
	 */
	@Column(name = "query_count", nullable = false, precision = 8, scale = 0, columnDefinition = "int(8) default '0'")
	private Integer queryCount;
	/**
	 * 状态"剩余"查询次数
	 */
	@Column(name = "query_remain", nullable = false, precision = 8, scale = 0, columnDefinition = "int(8) default '0'")
	private Integer queryRemain;
	/**
	 * 状态下次查询时间
	 */
	@Column(name = "query_time", nullable = false, columnDefinition = "datetime default '1970-01-01 00:00:00'")
	private Date queryTime;

	@PrePersist
	public void prePersist() {
		if (null == queryCount) {
			queryCount = 0;
		}
		if (null == queryRemain) {
			queryRemain = 10;
		}
		if (null == queryTime) {
			queryTime = new Date(System.currentTimeMillis() + (long)1e4);// 交易10秒之后再查
		}
	}

	public Integer getQueryCount() {
		return queryCount;
	}

	public void setQueryCount(Integer queryCount) {
		this.queryCount = queryCount;
	}

	public Integer getQueryRemain() {
		return queryRemain;
	}

	public void setQueryRemain(Integer queryRemain) {
		this.queryRemain = queryRemain;
	}

	public Date getQueryTime() {
		return queryTime;
	}

	public void setQueryTime(Date queryTime) {
		this.queryTime = queryTime;
	}

}